package com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.task;

import java.util.Iterator;
import java.util.List;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.Token;
import org.jbpm.graph.node.TaskNode;
import org.jbpm.taskmgmt.def.Task;
import org.jbpm.taskmgmt.exe.TaskMgmtInstance;

import com.tjsinfo.tjsoa.message.vo.TjsMessage;

public class BaseParallelTaskActionHandler implements ActionHandler{

	/* (non-Javadoc)
	 * @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext)
	 */
	public void execute(ExecutionContext executionContext) throws Exception {
		// TODO Auto-generated method stub
		TaskMgmtInstance taskMgmtInstance =	executionContext.getTaskMgmtInstance();
		Token token =	executionContext.getToken();
		TaskNode taskNode  =	(TaskNode) executionContext.getNode();
		Task task = (Task) taskNode.getTasks().iterator().next();
		List<String> list = (List<String>) executionContext.getVariable(executionContext.getNode().getName().trim());
		String flowName = (String) executionContext.getVariable("流程名称");
		if (flowName!=null && !"".equals(flowName)) {
			for (Iterator iterator = list.iterator(); iterator.hasNext();) {
				String id = (String) iterator.next();
				if(id != null && !"".equals(id)){
					taskMgmtInstance.createTaskInstance(task, token).setActorId(id);
					TjsMessage message1 = new TjsMessage();
					message1.setRecuserid(Integer.valueOf(id));
					message1.setValue("您有一个行政发文待办");
					TjsMessage.send(message1);
				}
			}
		}
	}
	
}
